/**
 * 
 */
package br.ufal.ic.sd.project.server.core;

import java.util.Properties;

import br.ufal.ic.sd.project.server.exception.ServerException;
import br.ufal.ic.sd.project.server.helper.Helper;
import br.ufal.ic.sd.project.server.util.Constants;

/**
 * @author keven andrade
 *
 */
public class TokenRing {
    
    private static Channel objChannel;
    
    public static void passToken(){
	
	objChannel = new Channel(getNextServerIP(),Integer.parseInt(getNextServerPort()));
	objChannel.connect();
	objChannel.write(getNextServerIP() + ":" + getNextServerPort());
	objChannel.close();
    }
    
    public static String getNextServerPort(){
	
	Properties objProperties = null;
	
	try {
	    objProperties = Helper.loadFile(Constants.SERVER_PROPERTIES);
	} catch (ServerException e) {
	    e.printStackTrace();
	}
	
	return objProperties.getProperty("nextToPassPort");
    }
    
    public static String getNextServerIP(){
	
	Properties objProperties = null;
	
	try {
	    objProperties = Helper.loadFile(Constants.SERVER_PROPERTIES);
	} catch (ServerException e) {
	    e.printStackTrace();
	}
	
	return objProperties.getProperty("nextToPassIP");
	
    }
    
    

}
